import KoaRouter from 'koa-router'
import Config from '@/config/Config'
import verifyToken from '@/middlewares/verifyToken'
import { Models } from '@/common/typings/modle'
import { command } from '@/server/mysql'
import { Account } from '@/common/typings/account'
import { Success } from '@/core/HttpException'
const router = new KoaRouter({
  prefix: `${Config.API_PREFIX}v1/system/user`,
})
router.post('/getById', verifyToken, async (ctx: Models.Ctx) => {
  const { id } = ctx.request.body as any
  const data = (
    await command(
      `SELECT u.user_name, u.id, u.created_at, u.updated_at, u.gender, u.gender_name, DATE_FORMAT(u.birth, '%Y-%m-%d') as birth, u.mobile, u.address, u.address_detail, u.marital_status, u.marital_status_name, u.email, u.status FROM system_user u WHERE u.id = '${id}';`,
      true,
    )
  ).results as Account.User[]
  throw new Success({
    data: data[0],
  })
})
export default router
